/**
 * 图片相关接口
 */
import request from '@/common/js/api.js'
import { Message } from 'element-ui'

// 公告图片上传
function requestUpload(imgList) {
  return new Promise((resolve, reject) => {
    const paramFormData = new FormData()
    imgList.forEach(v => {
      paramFormData.append('file', v)
    })
    request.post('/ly-oms-servicer/upload/image', paramFormData, res => {
      if (res.code == 0) {
        Message({
          type: 'success',
          message: res.message
        })
        resolve(res.responseBody)
      } else {
        Message({
          type: 'error',
          message: res.message
        })
        reject()
      }
    })
  })
}

// 订单图片上传
function reqUpload(imgList) {
  return new Promise((resolve, reject) => {
    const paramFormData = new FormData()
    if (Array.isArray(imgList)) {
      imgList.forEach(v => {
        paramFormData.append('file', v.file)
      })
    } else {
      paramFormData.append('file', imgList.file)
    }
    request.post('/ly-oms-servicer/upload/image', paramFormData, res => {
    //  console.log(res)
      if (res.code == 0) {
        Message({
          type: 'success',
          message: res.message
        })
        resolve(res.responseBody)
      } else {
        Message({
          type: 'error',
          message: res.message
        })
        reject()
      }
    })
  })
}

// 删除  monio 图片
function requestDel(url) {
  return new Promise((resolve, reject) => {
    request.get('/bds-oms-service/MinioController/clickDelete', { filePath: url }, res => {
      if (res.code == 0) {
        Message({
          type: 'success',
          message: res.message
        })
        resolve(true)
      } else {
        Message({
          type: 'error',
          message: res.message
        })
        reject()
      }
    })
  })
}
export { requestUpload, reqUpload, requestDel }
export default { requestUpload, reqUpload, requestDel }
